package com.rota.ssmreview.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rota.ssmreview.domain.Department;
import com.rota.ssmreview.mapper.DepartmentMapper;
import com.rota.ssmreview.query.PageResult;
import com.rota.ssmreview.query.QueryObject;
import com.rota.ssmreview.service.DepartmentService;

@Service
public class DepartmentServiceImpl implements DepartmentService {

	@Autowired
	private DepartmentMapper departmentMapper;
	
	public void save(Department entity) {
		departmentMapper.insert(entity);
	}

	public void update(Department entity) {
		departmentMapper.updateByPrimaryKey(entity);
	}

	public void delete(Long id) {
		departmentMapper.deleteByPrimaryKey(id);
	}

	public Department get(Long id) {
		return departmentMapper.selectByPrimaryKey(id);
	}

	public List<Department> list() {
		return departmentMapper.selectAll();
	}
	
	/* 分页查询数据 */
	public PageResult query(QueryObject qo) {

        int totalCount =  departmentMapper.selectForCount(qo);

        if(totalCount == 0){
            return PageResult.EMPTY_PAGE_RESULT;
        }

        List<Department> list = departmentMapper.selectForList(qo);
        return new PageResult(list, totalCount, qo.getCurrentPage(), qo.getPageSize());
    }

}
